var App = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    role_id:1,
    date_start:'',
    date_end:"",
    navBarHeight: 0,
    navigationBarHeight:0,
    date_type:1,
    class_type:1,
    date_title:'',
    lists:[],
    items: [
      {value: '1', name: '本日', checked: 'true'},
      {value: '2', name: '昨日'},
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      role_id: wx.getStorageSync('role_id')})
    if(this.data.role_id==1){
      this.setData({
        items: [
          {value: '1', name: '本日', checked: 'true'},
          {value: '2', name: '昨日'},
          {value: '3', name: '本月'},
          {value: '4', name: '上月'},
          {value: '5', name: '本年'},
          {value: '6', name: '全部'},
        ],
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    let that = this
    wx.getSystemInfo({
      success: function(res) {
        that.setData({
          navBarHeight: res.statusBarHeight,
          navigationBarHeight:res.statusBarHeight+44
        });
          console.log(res.statusBarHeight,res.statusBarHeight+44);
      },
      fail: function(err) {
          console.error(err);
      }
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getDataList()
  },
  bindDateChange: function(e) {
    this.setData({date_start: e.detail.value})
    this.getDataList()//获取数据列表
  },
  bindDateEChange: function(e) {
    this.setData({date_end: e.detail.value})
    this.getDataList()//获取数据列表
  },
  radioChange(e) {
    const items = this.data.items
    for (let i = 0, len = items.length; i < len; ++i) {
      items[i].checked = items[i].value === e.detail.value
    }
    this.setData({
      items,
      date_type:e.detail.value,
      date_start:'',
      date_end:''
    })
    this.getDataList()
  },
  backUrl(){
    let pages = getCurrentPages()
    console.log(pages)
    if(pages.length <2){
      wx.switchTab({
        url: '/pages/index/index',
      })
    }else{
      wx.navigateBack({
        delta: 1
      })
    }
  },
  changClass(e){
    this.setData({
      class_type:e.currentTarget.dataset.id
    })
    this.getDataList()
  },
  //获取数据列表
  getDataList(){
    let that = this;
    let obj = {
      b_id:App.get_b_id(),
      class_type:that.data.class_type,
      date_type:that.data.date_type,
      start_date:that.data.date_start,
      end_date:that.data.date_end
    }
    App.request('/Manage/Management/rankingList',obj,function(e){
      wx.stopPullDownRefresh()
        if (e.code == "200") {
          that.setData({
            lists:e.result.ranking,
            date_title:e.result.date_title
          })
        } 
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.getDataList();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})